<template>
  <h1>主页</h1>
  <div id="box" ref="myChart"></div>
  <div id="box2" ref="lineChart"></div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import echarts from "@/utils/echarts";

// 柱状图
let options = {
  title: {
    text: "ECharts 入门示例",
  },
  tooltip: {},
  xAxis: {
    data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
  },
  yAxis: {},
  series: [
    {
      name: "销量",
      type: "bar",
      data: [5, 20, 36, 10, 10, 20],
    },
  ],
};

const myChart = ref(null);
onMounted(() => {
  //   var myChart = echarts.init(document.getElementById("box"));
  console.log(myChart);
  let myChartObj = echarts.init(myChart.value);

  myChartObj.setOption(options);
});

// 折线图
let lineOptions = {
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [150, 230, 224, 218, 135, 147, 260],
      type: 'line'
    }
  ]
};

const lineChart = ref(null);
onMounted(() => {
  let myChartObj = echarts.init(lineChart.value);

  myChartObj.setOption(lineOptions);
});


</script>

<style scoped>
#box {
  width: 200px;
  height: 200px;
}
#box2 {
  width: 200px;
  height: 200px;
}
</style>
